#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int maxProfit(vector<int>& p, int fee) {
        int n = p.size();
        vector<int>dp1(n), dp2(n);
        dp1[0] = -p[0];
        for (int i = 1; i < n; i++)
        {
            dp1[i] = max(dp1[i - 1], dp2[i - 1] - p[i]);
            dp2[i] = max(dp2[i - 1], dp1[i - 1] + p[i] - fee);
        }
        return dp2[n - 1];
    }
};